<?php
/**
 * @author Michal Hantl
 * Created on 22.5.2006
 *
 */
 
class pStandard_Text extends cPart {

	function setElement(SimpleXMLElement $elm, $value, cView $view)
	{

		$path = $view->domPath->get();
		$first = array_shift($path);
		
		$fieldName = $first.'['.implode('][',$path).']';
		$id = $first.'_'.implode('_',$path);
		
		// <pluginy>

		//echo 'set Element héj?';
				
		$plugin = explode(',',$this->getAttr('plugins'));
		if ($plugin[0]=='') { 
			$plugin = array($this->getAttr('plugins')); 
		}
		$plugined = false;

		$fName = "get".$view->action."text";

		//print_r($plugin);
		
		
		foreach ($plugin as $p) 
		{
			if ($p=='') continue;
			if (!is_object($pObj = $this->cms->textPlugins[$p])) 
			{
				require_once(dirname(__FILE__).'/'.$p.'/'.$p.'.php');
				$cCLassName = $p.'Plugin';
				$pObj = $this->cms->textPlugins[$p] = new $cCLassName($this->cms);
			}
			if (method_exists($pObj, $fName)) 
			{
				$value = $pObj->$fName($fieldName, $id, $value, $view, $this);
				$plugined = true;
			} 
		}
		
		
		//die('2');
		
		
		// </pluginy>

		if (!$plugined) { $value = $this->$fName($fieldName, $id, $value, $view); }
		

		// pro XML výstupy
		if ($view->doctype!='xhtml' && $view->doctype!='raw' ) 
		{
			$value = htmlspecialchars($value);
		}
		
		return $elm->addChild($this->tagName, htmlspecialchars($value));
	}
	
	function getShowText($fieldName, $id, $value, cView $view)
	{
		return htmlspecialchars($value);
	}

	function getEditText($fieldName, $id, $value, cView $view)
	{
		if (($cols=$this->getAttr("cols"))=="") $cols = 20; 
		if (($rows=$this->getAttr("rows"))=="") $rows = 20;
		 
		$s="<fieldset class=\"textarea\" >
				<legend>
					<label for=\"".$id."\">".$this->getAttr("label")."</label>
				</legend>
				<textarea id=\"$id\" rows=\"".$rows."\" cols=\"".$cols."\" class=\"".$this->getAttr("class")."\"  name=\"".$fieldName."\">".htmlspecialchars($value)."</textarea>
			</fieldset>";
		return $s;
	}
	
}
 
?>